package cn.jbolt.ec.member;

import cn.jbolt._admin.permission.CheckPermission;
import cn.jbolt._admin.permission.PermissionKey;
import cn.jbolt.base.JBoltBaseController;
import cn.jbolt.common.bean.OptionBean;
import cn.jbolt.common.model.BecMember;
import com.jfinal.aop.Inject;

import java.util.ArrayList;
import java.util.List;

@CheckPermission(PermissionKey.MEMBER_ADMIN)
public class EcMemberAuthController extends JBoltBaseController {

    @Inject
    MemberService memberService;

    /**************************
     *  后台管理
     * @author heqingyu
     ****************
     */


    /**
     *  管理端主页
     */
    @CheckPermission({PermissionKey.MEMBER_INDEX})
    public void index(){
        keepPara();
        set("pageData", memberService.get_member_page(getPageNumber(),getPageSize(),getKeywords()));
//        set("deleteCount", memberService.get_delete_count());
        set("amount_balance",memberService.get_member_balance(getKeywords()));
        set("amount_credit",memberService.get_member_credit(getKeywords()));
        render("index.html");
    }


    /**
     * 编辑
     */

    public void modity(){
        set("member", memberService.findById(getInt(0)));
        render("modity.html");
    }


    /**
     * 更新
     */
    public void update_member(){
        renderJson(memberService.update_member(getSessionAdminUserId(),getModel(BecMember.class,"member"),
                getInt("isUpdateSpreader"),get("updateSpreader"),
                getInt("isUpdateBalance"),get("updateBalance")));
    }

    /**
     * select 编辑中 update 的下拉数据源
     */
    public void get_update_type(){
        List<OptionBean> options=new ArrayList<OptionBean>();
        options.add(new OptionBean("增加",1));
        options.add(new OptionBean("减少",2));
        renderJsonData(options);
    }

//    /**
//     * 删除商品
//     */
//    @CheckPermission({PermissionKey.MEMBER_DELETE_MEMBER})
//    public void delete_member(){
//        renderJson(memberService.delete_or_restore_member(getSessionAdminUserId(),getInt(0),1));
//    }
//
//
//    /**
//     * 恢复回收站里的一个商品
//     */
//    @CheckPermission(PermissionKey.MEMBER_RESTORE_MEMBER)
//    public void restore_member(){
//        renderJson(memberService.delete_or_restore_member(getSessionAdminUserId(),getInt(0),0));
//    }


    /**
     *   员工添加时需要
     *   会员数据源
     */
    public void options(){
        renderJsonData(memberService.getAutocompleteList(get("q"),getInt("limit",100),true,"id,nickname,mobile","nickname,mobile,title"));
    }

}
